package com.example.bankend.controller;



import com.example.bankend.model.Customer;
import com.example.bankend.service.impl.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Api(tags = "客户管理")
@RestController
@RequestMapping("/api/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    @ApiOperation(value = "新增客户数据")
    @PostMapping("/insert")
    public int insert(@RequestBody Customer customer) {
        System.out.println(customer.getTelephone());
        System.out.println(customer.getCustomerName());
        System.out.println(customer.getAddress());
        return customerService.insert(customer);
    }
    @ApiOperation(value = "根据客户ID进行删除")
    @DeleteMapping("/delete/{customerID}")
    public int deleteByPrimaryKey(@PathVariable Long customerID) {
        return customerService.deleteByPrimaryKey(customerID);
    }

    @ApiOperation(value = "根据客户ID进行更新")
    @PutMapping("/update/{customerID}")
    public int updateByPrimaryKey(@PathVariable Long customerID, @RequestBody Customer customer) {
        customer.setCustomerID(customerID); // 确保传入的 ID 与路径参数一致
        return customerService.updateByPrimaryKey(customer);
    }

    @ApiOperation(value = "根据客户ID进行查找")
    @GetMapping("/select/{customerID}")
    public String selectByPrimaryKey(@PathVariable Long customerID) {
        Customer customer = customerService.selectByPrimaryKey(customerID);
//        return customerService.selectByPrimaryKey(customerID);
        return customer.getTelephone();
    }
    @ApiOperation(value = "根据身份证ID进行查找")
    @GetMapping("/select1/{pid}")
    public String selectByPrimaryKey(@PathVariable String pid) {
        Customer customer = customerService.selectByPrimaryKey1(pid);
//        return customerService.selectByPrimaryKey(customerID);
        return customer.getTelephone();
    }
    @ApiOperation(value = "查询客户表里所有客户数量")
    @GetMapping("/count")
    public int countAllUsers() {
        return customerService.countAllUsers();
    }
    @ApiOperation(value = "获取所有客户信息")
    @GetMapping
    public List<Customer> selectAll() {
        return customerService.selectAll();
    }
}